package com.koron.css2.electronicCred.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.electronicCred.Enum.ProjectServiceEunm;
import com.koron.css2.electronicCred.bean.ElectronicCredRequestBean;
import com.koron.css2.electronicCred.service.ServicePool;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 获取授权信息
 *
 * @author 杨嘉慧
 * @date 2023/3/15
 */
public class GetAuthInfo implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            ElectronicCredRequestBean param = JsonUtils.objectToPojo(req.getData(), ElectronicCredRequestBean.class);
            return ServicePool.authInfoServices.get(ProjectServiceEunm.getServiceMark(param.getProjectType()) + "AuthInfoService")
                    .getAuthInfo(factory, userInfo, param);
        } catch (Exception e) {
            factory.close(false);
            logger.error("获取授权信息失败" + e.getMessage(), e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "获取授权信息失败", null);
        }
    }
}
